<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    //
    public function answers()
    {
        return $this->hasMany('\App\Model\Answer');
    }

    public function tags()
    {
        return $this->belongsToMany('\App\Model\Tag','article_tags','article_id','tag_id');
    }

    public function cate()
    {
        return $this->belongsTo('\App\Model\Cate');
    }

    public function topAnswer()
    {
        return $this->answers()->where('is_top',1)->first();
    }
}
